﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Practices.Unity;

using System.Web.UI.HtmlControls;

namespace Web
{
    public partial class mainPage : PageBase
    {

        private string LinkUrl = "Views/InfoRelease/QueryNewsInfo.aspx?PrimaryKey={0}&Handle=Query&NewsCategory=Docs";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //BindrpActive();
                //BindrpNotice();
                SetQuickMenuVisible();
                SetMenuVisible();
            }
        }

        #region 根据权限设置快捷菜单是否可见
        void SetQuickMenuVisible()
        {
           
        }
        /// <summary>
        /// 根据url获取menuId
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        string GetMenuIdByUrl(string url)
        {
            PageName = url.Remove(0, Request.ApplicationPath.Length + 1).Replace(".aspx", "");
            PageName = PageName.Replace("/", ".");
            return PageName;
        }
        #endregion

        #region 绑定事件
        private void BindrpNotice()
        {
            //DataTable newsList = iService.GetNoticePartInfo(8);
            //this.rpNotice.DataSource = newsList;
            //this.rpNotice.DataBind();
        }

        protected void rpNotice_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //找到该页的数据源
                DataRowView drv = (DataRowView)e.Item.DataItem;
                if (e.Item.FindControl("linkUrl").GetType() == typeof(HyperLink))
                {
                    HyperLink hl = (HyperLink)e.Item.FindControl("linkUrl");
                    System.Web.UI.HtmlControls.HtmlGenericControl span = (HtmlGenericControl)e.Item.FindControl("imgspan");
                    hl.ToolTip = drv["Title"].ToString();
                    hl.Text = drv["Title"].ToString();
                    double newsday = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["newsday"].ToString());
                    //加最新图标
                    if (DateTime.Parse(drv["CreateTime"].ToString()).AddDays(newsday) >= System.DateTime.Now)
                    {
                        span.InnerHtml= " <img  src='Images/new.gif' />";
                    }
                    //加载置顶信息
                    if (drv["IsTop"].ToString().ToBoolean() == true)
                    {
                        span.InnerHtml += " <img  src='Images/ding.gif' />";
                    }
                    hl.NavigateUrl = string.Format(LinkUrl, drv["AnnoNewsID"].ToString());
                }

            }
        }

        private void BindrpActive()
        {
            //DataTable newsList = iService.GetActivePartInfo(8);
            //this.rpActive.DataSource = newsList;
            //this.rpActive.DataBind();
        }

        protected void rpActive_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //找到该页的数据源
                DataRowView drv = (DataRowView)e.Item.DataItem;
                if (e.Item.FindControl("linkUrl").GetType() == typeof(HyperLink))
                {
                    HyperLink hl = (HyperLink)e.Item.FindControl("linkUrl");
                    System.Web.UI.HtmlControls.HtmlGenericControl span = (HtmlGenericControl)e.Item.FindControl("imgspan");
                    hl.ToolTip = drv["Title"].ToString();
                    hl.Text = drv["Title"].ToString();
                    double newsday = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["newsday"].ToString());
                    //加最新图标
                    if (DateTime.Parse(drv["CreateTime"].ToString()).AddDays(newsday) >= System.DateTime.Now)
                    {
                        span.InnerHtml= " <img  src='Images/new.gif' />";
                    }
                    //加载置顶信息
                    if (drv["IsTop"].ToString().ToBoolean() == true)
                    {
                        span.InnerHtml += " <img  src='Images/ding.gif' /> ";
                    }
                    hl.NavigateUrl = string.Format(LinkUrl, drv["AnnoNewsID"].ToString());
                }
            }
        }
        #endregion

        void SetMenuVisible()
        {
            try
            {
                if (!CheckMenuRight(this.aArchiveGloble.Attributes["href"].ToString()))
                {
                    this.lArchiveGloble.Visible = false;
                }
                if (!CheckMenuRight(this.aArchiveSearch.Attributes["href"].ToString()))
                {
                    this.lArchiveSearch.Visible = false;
                }
                if (!CheckMenuRight(this.aSingleWell.Attributes["href"].ToString()))
                {
                    this.lSingleWell.Visible = false;
                }
            }
            catch
            {
            }
        }
    }
}
